package com.ctshk.rpc.order.custom.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ctshk.rpc.order.custom.entity.CustomizedOrderReceiptDetails;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * <p>
 * 收据明细表、每一笔收据，产生一个数据 Mapper 接口
 * </p>
 *
 * @author 叶冠峰
 * @since 2021-03-02
 */
public interface CustomizedOrderReceiptDetailsMapper extends BaseMapper<CustomizedOrderReceiptDetails> {

    /**
     * 查询销售收据
     * @param id
     * @return
     */
    @Select("SELECT * FROM t_customized_order_receipt_details WHERE receipt_id = #{receipt_id} AND receipt_status = 1")
    CustomizedOrderReceiptDetails queryByReceipt(@Param("receipt_id") Long id);

    /**
     * 批量作废订单收据详情
     * @param orderId
     * @return
     */
    @Update("DELETE FROM t_customized_order_receipt_details\n" +
            "WHERE order_id = #{order_id}")
    Integer delByOrder(@Param("order_id")Long orderId);

    /**
     * 收据是否已开印花税
     * @param receiptId
     * @return
     */
    @Select("SELECT *\n" +
            "FROM t_customized_order_receipt_details\n" +
            "WHERE receipt_id = #{receipt_id} AND receipt_status = 1 AND is_print = 1 AND stamp_duty_pic IS NOT NULL LIMIT 1")
    CustomizedOrderReceiptDetails queryStampDutyReceipt(@Param("receipt_id")Long receiptId);
}
